

#include <p18f4550.h>
#include <delays.h>
#include "Timer_Driver.h"
#include "GPD_Driver.h"
#include "stdtypedef.h"
#include "Interruption_Driver.h"
#include "Core.h"
#include "ADC_Driver.h"
#include "Motores_Driver.h"
#include "CheckTime.h"
#include "Buttons_Driver.h"

	#pragma config WDT= OFF
	#pragma config PBADEN = OFF      
	#pragma config FOSC= INTOSCIO_EC  
	
extern T_UBYTE GPDin(T_UBYTE puerto);

enum Estados
{
	IDLE,
	Check500ms,
	Check1000ms,
	StartMotor,
	Scroll_1,
	Scroll_2,
} State;

enum BotonesW
{
	SinPresionar,
	UpPresionado,
	DownPresionado
} Botones;

void main(void)
{
	T_ULONG 	i=0,j=0;
	initcpu();
	initButtons();
	initMotores();
	//initCheckTime();
	INTCON = 0;
	INTCON2 = 0;
	T0CON = 0;
	initExtInt();
	initTimer0();
	Led = 1;
	//Time(2000);
	State = IDLE;
	Botones = SinPresionar;	
	while(1)
	{
		switch(State)
		{
			case IDLE:
				break;
			case Check500ms:
					if(i == 0)
					{
						Time(1000);
						i++;
						Led = 0;
					}
				break;
			case Check1000ms:
					if(j == 0)
					{
						Time(500);
						j++;
						Led = 1;
					}
				break;
			case StartMotor:
				if(BotonUp == 1)
				{
					if(SelectorUnipolar == 1)
						UpMotores(20,0);
					else if (SelectorBipolar == 1)
						BiUpMotores(20,0);
				}
				else if(BotonDown == 1)
				{
					if(SelectorUnipolar == 1)
						DownMotores(20,0);
					else if (SelectorBipolar == 1)
						BiDownMotores(20,0);
				}
				else State = IDLE;
				break;
			default:
				break;
					
		} 
	}
}


